package Reaction::InterfaceModel::Object;

use Reaction::InterfaceModel::ObjectClass;

class Object, which {

  has '_object_model' => (is => 'ro', required => 0, isa => 'Object');

  implements '_action_class_map' => as {
    return {};
  };

  implements '_default_action_class_for' => as {
    my ($self, $action) = @_;
    return $self->_default_action_class_prefix.'::Action::'.$action;
  };

  implements '_default_action_class_prefix' => as {
    my ($self) = @_;
    return (ref $self);
  };

  implements '_action_class_for' => as {
    my ($self, $action) = @_;
    if (defined (my $class = $self->_action_class_map->{$action})) {
      return $class;
    }
    return $self->_default_action_class_for($action);
  };

  implements 'action_for' => as {
    my ($self, $action, %args) = @_;
    my $class = $self->_action_class_for($action);
    %args = (
      %{$self->_default_action_args_for($action)},
      %args,
      %{$self->_override_action_args_for($action)},
    );
    return $class->new(%args);
  };

  implements '_default_action_args_for' => 
      as { return {target_model => $_[0]->_object_model } };

  implements '_override_action_args_for' => as { return {}; };

};

1;

__END__;


=head1 NAME

Reaction::Class::InterfaceModel::Object

=head1 SYNOPSIS

=head1 DESCRIPTION

InterfaceModel Object base class.

=head1 Attributes

=head2 _object_model

The object model that this interface model represents, e.g. a DBIC row 
or resultset object.

=head1 Methods

=head2 _action_class_map

Returns an empty hashref by default. It will hold a series of actions
as keys with their corresponding action classes as values.

=head2 _default_action_class_for $action

Provides the default package name for the C<$action> action-class.
It defaults to the value of C<_default_action_class_prefix> followed by
C<::Action::$action>

   #for MyApp::Foo, returns MyApp::Foo::Action::Create
   $obj->_default_action_class_for('Create');

=head2 _default_action_class_prefix 

Default action class prefix, defaults to the name of the current class,
i.e. C<ref $self> or C<$self-E<gt>blessed>.

=head2 _action_class_for $action

Return the action class for an action name. Will search 
C<_action_class_map> or, if not found, use the value of
C<_default_action_class_for>

=head2 action_for $action, %args

Will return a new instance of C<$action>. If specified,
 %args will be passed through to C<new> as is.

=head2 _default_action_args_for

By default will pass <_object_model> as C<target_model>

=head2 _override_action_args_for

Returns empty hashref by default.

=head1 SEE ALSO

L<Reaction::InterfaceModel::ObjectClass>

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut
